<?php
// +----------------------------------------------------------------------
// | Author: 玉林
// +----------------------------------------------------------------------

namespace app\admin\controller;

use think\Db;
use think\Cache;
use think\file;

class Setting extends Base
{

    //单位资质认证
    public function authentication_list()
    {
        $P = input('param.');
        $where = [];

        $list = Db::name('company_cert')->where($where)->select();
        $company_return =  Db::name('company')->where('')->field('company_name,company_id')->select();

        if($list) {
            if (!empty($list)) {
                foreach ($list as $key => $val) {
                    foreach ($company_return as $key2 => $val2) {
                        if($val['company_id'] == $val2['company_id']){
                            $list[$key]['company_name'] = $val2['company_name'];
                        }
                    }
                }
            }
        }

        $data = array(
            'code' => 1,
            'msg'  => 'ok',
            'time' => time(),
            'data' => $list
        );

        return json($data);
    }

    //查看认证资料详情
    public function watch_authentication()
    {
        $P = input('param.');
        $where = [];

        $P['company_cert_id'] && $where['company_cert_id'] = ['=',$P['company_cert_id']];

        $list = Db::name('company_cert')->where($where)->select();
        $company_return =  Db::name('company')->where('')->field('company_name,company_id')->select();

        if($list) {
            if (!empty($list)) {
                foreach ($list as $key => $val) {
                    foreach ($company_return as $key2 => $val2) {
                        if($val['company_id'] == $val2['company_id']){
                            $list[$key]['company_name'] = $val2['company_name'];
                        }
                    }
                }
            }
        }

        $this->assign('list',$list);

        return $this->out();
    }

    //认证通过
    public function check_authentication()
    {
        $P = input('param.');
        $where = [];

        $P['company_cert_id'] && $where['company_cert_id'] = ['=',$P['company_cert_id']];

        $car_use_cert_return = Db::name('company_cert')->where($where)->update(['state' => '1']);
        if($car_use_cert_return){
            return $this->success('认证成功','Setting/authentication');
        }
    }


}